package com.u.iot.engineering.controller;

import com.u.iot.engineering.entity.AiTask;
import com.u.iot.engineering.service.IAiTaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Alex Wu
 * @since 2025-03-24
 */
@RestController
@RequestMapping("/ai-task")
public class AiTaskController {

    @Autowired
    private IAiTaskService aiTaskService;

    @GetMapping
    public List<AiTask> getAllTasks() {
        return aiTaskService.list();
    }

    @GetMapping("/{id}")
    public AiTask getTaskById(@PathVariable Long id) {
        return aiTaskService.getById(id);
    }

    @PostMapping
    public void createTask(@RequestBody AiTask aiTask) {
        aiTaskService.save(aiTask);
    }

    @PutMapping("/{id}")
    public void updateTask(@PathVariable Long id, @RequestBody AiTask aiTask) {
        aiTask.setId(id);
        aiTaskService.updateById(aiTask);
    }

    @DeleteMapping("/{id}")
    public void deleteTask(@PathVariable Long id) {
        aiTaskService.removeById(id);
    }
}
